<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>珠峰培训零基础高薪就业班</title>
    <!-- IMPORT CSS -->
    <link rel="stylesheet" href="css/reset.min.css">
    <style>
        html,
        body {
            height: 100%;
        }

        .box {
            position: absolute;
            top: 20px;
            left: 100px;
            box-sizing: border-box;
            width: 100px;
            height: 100px;
            border: 2px solid rgb(112, 2, 2);
        }
    </style>
</head>

<body>
    <div class="box" draggable="true"></div>

    <!-- IMPORT JS -->
    <script>
        const box = document.querySelector('.box')
        box.addEventListener('dragstart', function (ev) {
            console.log(ev)
            this.style.background = 'pink'
            this.startX = ev.clientX
            this.startY = ev.clientY
        })
        box.addEventListener('drag', function (ev) {
            console.log('拖拽中：', ev)
            this.style.left = 100 + ev.clientX - this.startX + 'px'
            this.style.top = 20 + ev.clientY - this.startY + 'px'
        })
        box.addEventListener('dragend', function (ev) {
            this.style.left = ev.clientX - this.startX + 'px'
            this.style.top = ev.clientY - this.startY + 'px'
        })
    </script>
</body>

</html>